package com.iworkh.spring.web.mvc.controller;

import com.iworkh.spring.web.mvc.domain.vo.Site;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.util.Map;

/**
 * SessionController
 *
 * @author: iworkh-沐雨云楼
 * @date: 2019-12-27
 */

@Controller
@RequestMapping("/springmvc")
@SessionAttributes(value = {"siteIworkh","siteBaidu"})
// @SessionAttributes(types = {Site.class})
public class SessionAttributesController {

    @RequestMapping("/testSessionAttributes")
    public String testSessionAttributes(Map<String, Site> map) {
        System.out.println("iworkh--testSessionAttributes");
        // 如果该类有 @SessionAttribute 注解，会同时将value或者type值存放到request作用域和session作用域
        // 否则将对象放到 request 作用域。
        Site siteIworkh = Site.builder().name("iworkh-沐雨云楼").url("https://www.iworkh.com").build();
        Site siteBaidu = Site.builder().name("百度").url("https://www.baidu.com").build();
        map.put("siteIworkh", siteIworkh);
        map.put("siteBaidu", siteBaidu);
        return "success";
    }
}

